package leetcode.剑指offer.后40;

import org.junit.Test;

import java.util.Arrays;

/**
 * @author :songyaozhang
 * @date :Created 2021/8/2 9:18
 * @description :https://leetcode-cn.com/problems/bu-ke-pai-zhong-de-shun-zi-lcof/
 */
public class 剑指_61_扑克牌中的顺子 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.isStraight(new int[]{0,0,1,2,5}));
    }

    class Solution {
        public boolean isStraight(int[] nums) {
            int count0 = 0;
            int count = 0;
            Arrays.sort(nums);
            int pre = 0;
            for (int num : nums) {
                if (num == 0) {
                    count0++;
                } else if (pre == 0) {
                    pre = num;
                } else if (num == pre){
                    return false;
                } else {
                    count += num - pre - 1;
                    pre = num;
                }
            }
            return count0 >= count;
        }
    }


}
